unit Con_Ficha;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Formulario_Padrao_Consulta, StdCtrls, Buttons, ExtCtrls, Grids, DBGrids,
  Db, Dbtables;

type
  TFrmCon_Ficha = class(TFrmConsulta)
    EdtDescricao: TEdit;
    Label1: TLabel;
    DbgComp: TDBGrid;
    procedure BtnFecharClick(Sender: TObject);
    procedure EdtDescricaoKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FormActivate(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
    procedure FazConsulta;
  public
    { Public declarations }
    Var_codigo : String;
    Pro_codigo : String;
    Pro_codigo2 : String;
  end;

var
  FrmCon_Ficha: TFrmCon_Ficha;

implementation

Uses Dm, Biblio, clsFicha, clsProduto;

{$R *.DFM}

var Produto   : TProduto;
    tds       : Tdatasource;
    tq        : Tquery;

procedure TFrmCon_Ficha.BtnFecharClick(Sender: TObject);
begin
  inherited;
  Pro_codigo2:=tq.fieldbyname('Pro_codigo2').asstring;
  tds.free;
  tq.free;
end;

procedure TFrmCon_Ficha.EdtDescricaoKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  inherited;
  if key=12 then begin
    FazConsulta;
    EdtDescricao.setfocus;
  end;
end;

procedure TFrmCon_Ficha.FormActivate(Sender: TObject);
begin
  inherited;
  tds:=TDataSource.create(FrmCon_Ficha);
  tq:=Tquery.create(FrmCon_Ficha);
  tq.databasename:=dmint.db.databasename;
  tq.active:=False;
  tds.DataSet:=tq;
  fazconsulta;
  EdtDescricao.setfocus;
end;

procedure TFrmCon_Ficha.FazConsulta;
var xconjunto : integer;
    xpro_codigo : String;
begin
  xconjunto:= 0;
  if EdtDescricao.text='' then
    EdtDescricao.text := ' ';
  Produto.Recuperar(Pro_codigo);
  if xconjunto = 0 then begin
    //ItemFicha.Consultar(tq,Pro_codigo,Var_codigo,' ');
    tq.open;
    xpro_codigo := tq.fieldbyname('Pro_codigo2').asstring;
    tq.close;
  end;
  if xconjunto = 0 then
    //ItemFicha.Consultar(tq,xpro_codigo,Var_codigo,EdtDescricao.text)
  else
    //ItemFicha.Consultar(tq,Pro_codigo,Var_codigo,EdtDescricao.text);
  tq.open;
  dbgComp.DataSource := tds;
  dbgComp.Refresh;
end;

procedure TFrmCon_Ficha.FormCreate(Sender: TObject);
begin
  inherited;
	Produto := TProduto.Create;

end;

procedure TFrmCon_Ficha.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  inherited;
	Produto.free;
end;
end.
